<?php
$this->pageTitle=Yii::app()->name . ' - Giải bài tập';
$this->breadcrumbs = array(
	
);
?>
<div class="well">
	<div class="navbar">
		<div class="navbar-inner"><i class="icon-chevron-right icon-white"></i> Giải bài tập</div>
	</div>
	<div class="row-fluid">
		<?php
    	if(Yii::app()->user->hasFlash('success')) {
    		echo '<div class="alert alert-success">'.Yii::app()->user->getFlash('success').'</div>';
    	} 
    	if(Yii::app()->user->hasFlash('no-balance')) {
    	  echo '<div class="alert alert-block">'.Yii::app()->user->getFlash('no-balance').'</div>';
    	  echo '<a href="'.Yii::app()->baseUrl.'/user/balance#deposit"><button class="btn btn-danger">Nạp thẻ</button></a>';
    	}
    	else {
    ?>
		 <?php
    $form=$this->beginWidget('CActiveForm', array(
    'id'=>'issue-submit-form',
    'htmlOptions'=>array('enctype'=>'multipart/form-data','class'=>'form-horizontal'),
  )); 
    ?>
    <?php
    $this->widget('ext.ajaxform.JAjaxForm',array(
      'formId'=>'issue-submit-form',
      'options'=>array(
        'dataType'=>'json',
        'beforeSubmit'=>'js:function(formData,$form,options) { before_submit(); }',
        'success'=>'js:function(responseText,statusText) {
        	if(responseText.result.error) {
        		$("#img_captcha").trigger("click");
        		$("input#Issue_captcha").attr("value","");
        		error_submit(responseText.result.error);
        	}
        	if(responseText.result.success) {
        		success_submit(responseText.result.success,"/issue/submit");
        	}
        }',
        'error'=>'js:function(responseText,statusText) {
        	$("#img_captcha").trigger("click");
        	$("input#Issue_captcha").attr("value","");
        	error_submit(responseText.responseText);
        }'
      )
    ));
    ?>
			<p class="note">Những trường đánh dấu <span class="required">*</span> là trường bắt buộc.</p>
			<?php //echo $form->errorSummary(array($model),"","",array('class'=>'alert alert-error')); ?>
			<div id="div-result"></div>
	    <div class="control-group">
	    	<?php echo $form->labelEx($model,'gradeID',array('class'=>'control-label')); ?>
		    <?php echo $form->dropdownList($model,'gradeID',Grade::model()->getListGrade(),array('prompt'=>'Chọn lớp','required'=>'required'))?>
	   	</div>
	  
	    <div class="control-group">
	    	<?php echo $form->labelEx($model,'subjectID',array('class'=>'control-label')); ?>
		    <?php echo $form->dropdownList($model,'subjectID',Subject::model()->getListSubject(),array('prompt'=>'Chọn môn học','required'=>'required'))?>
      </div>
	    
      <div class="control-group">
      	<?php echo $form->labelEx($model,'quantity_object',array('class'=>'control-label')); ?>
		    <?php echo $form->dropdownList($model,'quantity_object',$model->getQuantity())?>
	   	</div>
	   	
	   	<div class="control-group">
      	<?php echo $form->labelEx($model,'emergency',array('class'=>'control-label')); ?>
		    <?php echo $form->dropdownList($model,'emergency',$model->getEmergency())?>
	   	</div>
	   	
	   	<div class="control-group">
      	<?php echo $form->labelEx($model,'content',array('class'=>'control-label')); ?>
      	<?php //echo $form->textArea($model,'content',array('id'=>'editor')); ?>
      	<div class="clearfix"></div>
      	<?php
      		$this->widget('ext.ckeditor.CKEditorWidget',array(
            "model"=>$model,
            "attribute"=>'content',
          	"config" => array(
      	      "toolbar"=>"Full",
      				"height"=>"400px",
      				'width'=>"95%",
      				//'contentsCss'=>Yii::app()->baseUrl.'/themes/admin/views/css/form.css',
      				//'bodyClass'=>'ckeditor'
          ),
          )); 
      	?>
	   	</div>
	  	
	  	<div class="control-group">
	  		<?php echo $form->labelEx($model,'image',array('class'=>'control-label')); ?>
	  		<?php $this->widget('CMultiFileUpload', array(
								'model'=>$model,// dong nay lam gi>
                'attribute' => 'image',
								'max'=>5,// gioi han so luong file?
                'accept' => 'jpeg|gif|png|jpg', // useful for verifying files
                'duplicate' => 'File bị trùng, vui lòng chọn lại!', // useful, i think
                'denied' => 'File không hợp lệ', // useful, i think
	  		        'remove'=>'<i class="icon-remove"></i>',
              ));
      ?>  
      <p class="note">Chấp nhận file: jpg, jpeg, gif, png</p>
  		</div>
	
	  	<?php if(CCaptcha::checkRequirements()) { ?>
      <div class="control-group clearfix">
        <?php echo $form->labelEx($model,'captcha',array('class'=>'control-label')); ?>
        <div class="captcha">
        <?php $this->widget('CCaptcha', array(
            'buttonLabel'=>'<i class="icon-refresh"></i>',
            'clickableImage'=>true,
        		'imageOptions'=>array('id'=>'img_captcha')
        )); ?>
        <?php echo $form->textField($model,'captcha', array('autocomplete'=>'off','required'=>'required')); ?>
        </div>
        <div class="hint">
        	Vui lòng nhập những ký tự ở hình bên trên. <br>
        	Không phân biệt chữ hoa chữ thường.
        </div>
      </div>
      <?php } ?>
			<?php echo CHtml::submitButton('Gửi issue', array('class'=>'btn btn-success','onclick'=>'javascript:CKupdate();')); ?>
		<?php $this->endWidget(); ?>
		<?php } ?>
	</div>
</div>
<script type="text/javascript">
$(function() {
	$(window).load(function(){
		$("#img_captcha").trigger("click");
	});
});
function CKupdate(){
  for (instance in CKEDITOR.instances)
      CKEDITOR.instances[instance].updateElement();
}
</script>
